﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RobotMapper;
using Entity;

namespace Test
{
    [TestClass]
    public class 配置测试
    {
        [TestMethod]
        public void 测试配置Bind()
        {
            Mapper.Initialize(creator =>
            {
                creator.CreatMap<User, DTO.User>(config =>
                {
                    config.Bind(x => x.User12.Name, y => y.UserName);
                    config.Bind(x => x.User12.Name, y => y.UserName);
                    config.Ignore(y => y.Roles);
                });
            });
        }

        [TestMethod]
        public void 测试配置规则转换()
        {
            Mapper.Initialize(creator =>
            {
                creator.CreatMap<User, DTO.User>(config =>
                {
                    config.Bind(x => x.User12.Name, y => y.UserName);
                });
            });
            var user = TestHelper.创建自引用User();
            var newuser = user.RobotMap<User, DTO.User>();
            Assert.AreEqual(user.User12.Name, newuser.UserName);
        }

        [TestMethod]
        public void 测试忽略规则转换()
        {
            Mapper.Initialize(creator =>
            {
                creator.CreatMap<User, DTO.User>(config =>
                {
                    config.Ignore(y => y.Code);
                    config.Ignore("Department", "Name");
                });
            });
            var user = TestHelper.创建扁平化User();
            var newuser = user.RobotMap<User, DTO.User>();
            Assert.IsNull(newuser.Code);
            Assert.IsNull(newuser.Department);
            Assert.IsNull(newuser.Name);
        }
    }
}